<template>
	<view class="myCollectionList">
		<!-- <header-box :title="pageTitle"></header-box> -->
		<view class="fixed-box">
			<view class="switch-box">
				<view :class="['item',type == 0 ? 'active' : '']" @tap="switchFun(0)">我的藏品</view>
				<view :class="['item',type == 1 ? 'active' : '']" @tap="switchFun(1)">超级权益卡</view>
				<view :class="['item',type == 2 ? 'active' : '']" @tap="switchFun(2)">我的盲盒</view>
				<view class="line" :style="{left:lineLift}"></view>
			</view>
		</view>
		<view class="myCollectionList-box">
			<mescroll-uni ref="mescrollRef" :isBack="true" @init="mescrollInit" height="100%" :top="mescrollUni_Top" :bottom="mescrollUniBottom" :total="total" :down="downOption" @down="downCallback" :up="upOption" @up="upCallback" @emptyclick="emptyClick">
				<view class="myCollectionList-main">
					<view class="_main-item" @click="toCollectionDetail(item)" v-if="type != 1 && type != 2 && list.length>0" v-for="item,index in list" :key="index">
						<view class="_main-item-goods"><image class="_main-item-goods-img" :src="item.img" mode=""></image></view>
						<view class="_main-item-title single-line"><text>{{item.name}}</text></view>
					</view>
					<view class="_main-content-item" v-if="type == 1 && cardList.length>0" v-for="item,index in cardList" :key="index">
						<image class="_item-img" :src="item.cardImg" mode=""></image>
						<view class="_item-detail">
							<view class="_item-detail-title"><text>{{item.cardName}}</text></view>
							<view class="_item-detail-num"><text>数量：{{item.cardNum}}</text></view>
						</view>
					</view>
					<view class="blindBoxList-main-item" v-if="type == 2 && blindList.length>0" v-for="item,index in blindList" :key="index" @click="openBox(item)">
						<view class="blindBoxList-main-item-box">
							<view class="blindBoxList-main-item-goods">
								<image class="blindBoxList-main-item-goods-img noSaveImg" :src="item.boxImg" mode=""></image>
							</view>
							<view class="blindBoxList-main-item-info">
								<view class="blindBoxList-main-item-info-title single-line"><text>{{item.boxName}}</text></view>
								<view class="blindBoxList-main-item-info-num single-line"><text>数量：{{item.num}}</text></view>
								<view class="blindBoxList-main-item-info-price">
									<text>待开启</text>
									<view class="blindBoxList-main-item-info-price-line"></view>
								</view>
							</view>
						</view>
					</view>
				</view>
				<!-- <view class="myCollectionList-main" v-if="type == 1 && cardList.length>0">
					<view class="_main-content-item" v-for="item,index in cardList" :key="index">
						<image class="_item-img" :src="item.cardImg" mode=""></image>
						<view class="_item-detail">
							<view class="_item-detail-title"><text>{{item.cardName}}</text></view>
							<view class="_item-detail-num"><text>数量：{{item.cardNum}}</text></view>
						</view>
					</view>
				</view> -->
				<!-- <view class="blindBoxList-main" v-if="type == 2 && blindList.length>0">
					<view class="blindBoxList-main-item" v-for="item,index in blindList" :key="index" @click="openBox(item)">
						<view class="blindBoxList-main-item-box">
							<view class="blindBoxList-main-item-goods">
								<image class="blindBoxList-main-item-goods-img noSaveImg" :src="item.boxImg" mode=""></image>
							</view>
							<view class="blindBoxList-main-item-info">
								<view class="blindBoxList-main-item-info-title single-line"><text>{{item.boxName}}</text></view>
								<view class="blindBoxList-main-item-info-num single-line"><text>数量：{{item.num}}</text></view>
								<view class="blindBoxList-main-item-info-price">
									<text>待开启</text>
									<view class="blindBoxList-main-item-info-price-line"></view>
								</view>
							</view>
						</view>
					</view>
				</view> -->
			</mescroll-uni>
		</view>
	</view>
</template>

<script>
	import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
	import MescrollMoreItemMixin from "@/components/mescroll-uni/mixins/mescroll-more-item.js";
	export default {
		mixins: [MescrollMixin,MescrollMoreItemMixin], // 注意此处还需使用MescrollMoreItemMixin (必须写在MescrollMixin后面)
		data() {
			return {
				type:0,//0我的藏品 1超级权益卡,
				pageTitle:'藏品清单',
				total:0,
				list:[],
				params:{
					page:1,
					pageSize:8,
				},
				downOption:{
					auto:false // 不自动加载 (mixin已处理第一个tab触发downCallback)
				},
				upOption:{
					auto:false, // 不自动加载
					page: {
						num: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
						size: 10 // 每页数据的数量
					},
					noMoreSize: 6, //如果列表已无数据,可设置列表的总数量要大于半页才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看; 默认5
					toTop:{
						offset:400,
					},
					empty:{
						tip: '~ 空空如也 ~', // 提示
						btnText: ''
					},
					elItem:{
						top:256,
						height:265,
						rowNum:2,
					}
				},
				mescrollUni_Top:86,
				mescrollUniBottom:0,
				cardList:[],
				blindList:[],
				urlData:null,
			};
		},
		computed: {
			lineLift() {
				return 100/3.8*(this.type + 1) - 100/(3.8*2) + '%'
			}
		},
		onLoad(option) {
			this.urlData = this.$util.getUrlVal();
			if (this.urlData.out_trade_no) {
				this.$api.getOrderByOutTradeNo({outTradeNo:this.urlData.out_trade_no}).then(res => {
					console.log(res)
					if (res.code == 200) {
						if (res.data.orderType == 1) {
							this.type = 0;
						}
						if (res.data.orderType == 2) {
							this.type = 2;
						}
						this.switchFun(this.type)
					}
				})
			} else {
				if (option.type) {
					this.type = option.type - 1;
				} else {
					this.type = 0;
				}
			}
		},
		mounted() {
			if (!this.urlData || !this.urlData.out_trade_no) {
				this.switchFun(this.type)
			}
			// this.mescroll.setPageNum(1)
			// this.mescroll.resetUpScroll(true)
			// this.mescroll.scrollTo(0,300)
		},
		methods:{
			//搜索类型
			switchFun(type){
				this.type = type
				this.params.page = 1;
				this.mescroll.setPageNum(1)
				this.mescroll.resetUpScroll(true)
				this.mescroll.scrollTo(0,300)
			},
			/*下拉刷新的回调 */
			downCallback() {
				// 这里加载你想下拉刷新的数据, 比如刷新轮播数据
				// loadSwiper();
				// 下拉刷新的回调,默认重置上拉加载列表为第一页 (自动执行 page.num=1, 再触发upCallback方法 )
				this.mescroll.resetUpScroll()
			},
			/*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
			upCallback(page) {
				// console.log(page.num)
				this.params.page = page.num
				this.getList()
			},
			//点击空布局按钮的回调
			emptyClick(){
				uni.showToast({
					title:'点击了按钮,具体逻辑自行实现'
				})
			},
			//获取订单列表
			getList(){
				this.mescroll.lockUpScroll(true)
				if (this.type != 1 && this.type != 2) {
					this.$api.getMyCollection(this.params).then(res => {
						console.log(res)
						let curLen = this.list.length
						let totalPage
						if(res.code == 200){
							if(this.params.page == 1) this.list = []
							this.list = this.list.concat(res.data.collectionInfoList)
							curLen = this.list.length
							totalPage = Math.ceil(res.data.total / this.params.pageSize)
							setTimeout(() => {
								this.mescroll.endByPage(curLen, totalPage);
							},200)
							this.total = res.data.total
						}
						// console.log(this.upOption.toTop)
						// this.mescroll.endSuccess(curLen)
						setTimeout(() => {
							this.mescroll.lockUpScroll(false)
						},800)
					},err => {
						setTimeout(() => {
							this.mescroll.lockUpScroll(false)
						},800)
						this.mescroll.endErr()
					})
				} else {
					if (this.type == 1) {
						this.$api.getMyCardList(this.params).then(res => {
							console.log(res)
							let curLen = this.cardList.length
							let totalPage
							if(res.code == 200){
								if(this.params.page == 1) this.cardList = []
								this.cardList = this.cardList.concat(res.data.cardList)
								curLen = this.cardList.length
								totalPage = Math.ceil(res.data.total / this.params.pageSize)
								setTimeout(() => {
									this.mescroll.endByPage(curLen, totalPage);
								},200)
								this.total = res.data.total
							}
							// console.log(this.upOption.toTop)
							// this.mescroll.endSuccess(curLen)
							setTimeout(() => {
								this.mescroll.lockUpScroll(false)
							},800)
						},err => {
							setTimeout(() => {
								this.mescroll.lockUpScroll(false)
							},800)
							this.mescroll.endErr()
						})
					}
					if (this.type == 2) {
						this.$api.myGiftBox(this.params).then(res => {
							console.log(res)
							let curLen = this.blindList.length
							let totalPage
							if(res.code == 200){
								if(this.params.page == 1) this.blindList = []
								this.blindList = this.blindList.concat(res.data.records)
								curLen = this.blindList.length
								totalPage = Math.ceil(res.data.total / this.params.pageSize)
								setTimeout(() => {
									this.mescroll.endByPage(curLen, totalPage);
								},200)
								this.total = res.data.total
							}
							// console.log(this.upOption.toTop)
							// this.mescroll.endSuccess(curLen)
							setTimeout(() => {
								this.mescroll.lockUpScroll(false)
							},800)
						},err => {
							setTimeout(() => {
								this.mescroll.lockUpScroll(false)
							},800)
							this.mescroll.endErr()
						})
					}
				}
			},
			toCollectionDetail(item) {
				uni.navigateTo({
					url:`/pages/myCollectionDetail/myCollectionDetail?relId=${item.relId}&from=1`
				})
			},
			openBox(item) {
				uni.redirectTo({
					url:`/pages/openBox/openBox?num=${item.num}&boxId=${item.boxId}`
				})
			}
		}
	}
</script>

<style lang="less">
	.myCollectionList{
		width: 100%;
		min-height: 100vh;
		background-color: #16181D;
		font-family: PingFangSC-Medium, PingFang SC, '微软雅黑';
		font:caption;
		display: flow-root;
		.fixed-box{
			position: fixed;
			// top: var(--window-top);
			// top:88rpx;
			top: 0;
			z-index: 999;
			left: 0;
			width: 100%;
			.switch-box{
				display: flex;
				height:87rpx;
				line-height: 87rpx;
				font-size: 32rpx;
				background: #16181D;
				position: relative;
				.item{
					// width: 33.3%;
					width: 26.6%;
					color: #5E6272;
					text-align: center;
				}
				.line{
					position: absolute;
					width:64rpx;
					height:4rpx;
					background:rgba(255,255,255,1);
					left: 50%;
					bottom: 0;
					transform: translateX(-50%);
					transition: left .3s;
				}
				.active{
					color: #ffffff;
					position: relative;
				}
			}
		}
		.myCollectionList-box{
			width: 100%;
			// margin-top: 87rpx;
			.myCollectionList-main{
				padding: 0 32rpx;
				box-sizing: border-box;
				display: flex;
				flex-direction: column;
				._main-item{
					margin-top: 32rpx;
					width: 100%;
					height: 822rpx;
					background: #262A34;
					border-radius: 40rpx;
					._main-item-goods{
						width: 100%;
						height: 686rpx;
						border-radius: 40rpx;
						overflow: hidden;
						._main-item-goods-img{
							width: 100%;
							height: 100%;
						
						}
					}
					._main-item-title{
						font-size: 32rpx;
						font-weight: 500;
						color: #FFFFFF;
						line-height: 56rpx;
						text-align: center;
						margin-top: 32rpx;
					}
				}
				._main-content-item{
					width: 100%;
					padding: 32rpx;
					box-sizing: border-box;
					display: flex;
					flex-wrap: nowrap;
					justify-content: flex-start;
					align-items: center;
					background: #262A34;
					border-radius: 40rpx;
					margin-top: 32rpx;
					._item-img{
						width: 100rpx;
						height: 100rpx;
						border-radius: 30rpx;
					}
					._item-detail{
						width: calc(100% - 132rpx);
						margin-left: 32rpx;
						._item-detail-title{
							font-size: 32rpx;
							font-weight: 400;
							color: #FFFFFF;
							line-height: 56rpx;
						}
						._item-detail-num{
							font-size: 28rpx;
							font-weight: 400;
							color: #5D5F7A;
							line-height: 40rpx;
							margin-top: 4rpx;
						}
					}
				}
			}
			
			.blindBoxList-main{
				width: 100%;
				padding: 0 32rpx;
				box-sizing: border-box;
				.blindBoxList-main-item{
					width: 100%;
					height: 330rpx;
					display: flex;
					flex-direction: column;
					justify-content: flex-end;
					margin-top: 32rpx;
					.blindBoxList-main-item-box{
						height: 276rpx;
						background: #262A34;
						border-radius: 40rpx;
						display: flex;
						flex-wrap: nowrap;
						justify-content: space-between;
					}
					.blindBoxList-main-item-goods{
						width: 332rpx;
						height: 100%;
						position: relative;
						.blindBoxList-main-item-goods-img{
							width: 300rpx;
							height: 300rpx;
							position: absolute;
							top: -54rpx;
							left: 32rpx;
							border-radius: 40rpx;
						}
					}
					.blindBoxList-main-item-info{
						width: calc(100% - 332rpx);
						padding: 32rpx 0 0 40rpx;
						box-sizing: border-box;
						.blindBoxList-main-item-info-title{
							font-size: 32rpx;
							font-family: PingFangSC-Regular, PingFang SC, '微软雅黑';
							font-weight: 400;
							color: #FFFFFF;
							line-height: 56rpx;
						}
						.blindBoxList-main-item-info-num{
							font-size: 28rpx;
							font-family: PingFangSC-Regular, PingFang SC, '微软雅黑';
							font-weight: 400;
							color: #5D5F7A;
							margin-top: 4rpx;
						}
						.blindBoxList-main-item-info-price{
							font-size: 36rpx;
							font-family: Inter-Bold, Inter;
							font-weight: 400;
							color: #A06AF9;
							text-shadow: 0px 16rpx 32rpx rgba(0, 0, 0, 0.5);
							position: relative;
							margin-top: 60rpx;
							.blindBoxList-main-item-info-price-line{
								width: 80rpx;
								height: 20rpx;
								background: #86E9A4;
								box-shadow: 0px 16rpx 32rpx 0px rgba(0, 0, 0, 0.5);
								opacity: 0.05;
								position: absolute;
								bottom: -8rpx;
								left: 0;
							}
						}
					}
				}
			}
			.blindBoxList-main-item{
				width: 100%;
				height: 330rpx;
				display: flex;
				flex-direction: column;
				justify-content: flex-end;
				margin-top: 32rpx;
				.blindBoxList-main-item-box{
					height: 276rpx;
					background: #262A34;
					border-radius: 40rpx;
					display: flex;
					flex-wrap: nowrap;
					justify-content: space-between;
				}
				.blindBoxList-main-item-goods{
					width: 332rpx;
					height: 100%;
					position: relative;
					.blindBoxList-main-item-goods-img{
						width: 300rpx;
						height: 300rpx;
						position: absolute;
						top: -54rpx;
						left: 32rpx;
						border-radius: 40rpx;
					}
				}
				.blindBoxList-main-item-info{
					width: calc(100% - 332rpx);
					padding: 32rpx 0 0 40rpx;
					box-sizing: border-box;
					.blindBoxList-main-item-info-title{
						font-size: 32rpx;
						font-family: PingFangSC-Regular, PingFang SC, '微软雅黑';
						font-weight: 400;
						color: #FFFFFF;
						line-height: 56rpx;
					}
					.blindBoxList-main-item-info-num{
						font-size: 28rpx;
						font-family: PingFangSC-Regular, PingFang SC, '微软雅黑';
						font-weight: 400;
						color: #5D5F7A;
						margin-top: 4rpx;
					}
					.blindBoxList-main-item-info-price{
						font-size: 36rpx;
						font-family: Inter-Bold, Inter;
						font-weight: 400;
						color: #A06AF9;
						text-shadow: 0px 16rpx 32rpx rgba(0, 0, 0, 0.5);
						position: relative;
						margin-top: 60rpx;
						.blindBoxList-main-item-info-price-line{
							width: 80rpx;
							height: 20rpx;
							background: #86E9A4;
							box-shadow: 0px 16rpx 32rpx 0px rgba(0, 0, 0, 0.5);
							opacity: 0.05;
							position: absolute;
							bottom: -8rpx;
							left: 0;
						}
					}
				}
			}
		}
	}
</style>
